package cn.chinasyq.photoquan.news.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.android.volley.toolbox.NetworkImageView;
import com.bigkoo.convenientbanner.CBPageAdapter;

import cn.chinasyq.photoquan.R;
import cn.chinasyq.photoquan.news.bean.BannersEntity;
import cn.master.volley.commons.VolleyHelper;

/**
 * Created by Sai on 15/8/4.
 * 网络图片加载例子
 */
public class NetworkImageHolderView implements CBPageAdapter.Holder<BannersEntity> {
    private NetworkImageView imageView;

    @Override
    public View createView(final Context context) {
        //你可以通过layout文件来创建，也可以像我一样用代码创建，不一定是Image，任何控件都可以进行翻页
        imageView = new NetworkImageView(context);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        imageView.setDefaultImageResId(R.drawable.bg_default);
        imageView.setErrorImageResId(R.drawable.bg_default);
        return imageView;
    }

    @Override
    public void UpdateUI(Context context, int position, BannersEntity data) {
        imageView.setImageUrl(data.getImage(), VolleyHelper.getImageLoader());
        imageView.setTag(data);
    }
}
